<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        //await表达式必须写在async函数中
        //await右侧表达式一般是promise对象
        //await返回值是promise成功的值
        //await的promise失败了，就会抛出异常，可以用trycatch捕获

        let p = new Promise((resolve,reject)=>{
            //resolve('成功的值')
            reject('失败了')
        })

        async function main() {
            try{
                let res = await p;
                console.log(res) //成功的值
            }catch(e){
                console.warn(e) //失败了
            }
        }

        main()
    </script>
</body>
</html>